const electron = require("electron");
const path = require("path");

electron.protocol.registerSchemesAsPrivileged([
    {
        scheme: 'fep',
        privileges: {
            standard: true,
            secure: true,
            supportFetchAPI: true
        }
    }
]);

electron.app.whenReady().then(r => {
    const APP_ROOT = electron.app.getAppPath();

    electron.protocol.registerFileProtocol("fep", (req, callback) => {
        let url = new URL(req.url);
        let relativePath = url.pathname;
        if (relativePath.startsWith("/")) {
            relativePath = relativePath.substring(1);
        }
        callback({ path: path.join(APP_ROOT, relativePath) });
    });

    let window = new electron.BrowserWindow({
        width: 800,
        height: 600
    });
    window.on("closed", e => { electron.app.exit(0) });
    window.loadURL("fep://approot.com/index.html");
});